package com.example.controller;

import com.example.entity.ReimbursementRecord;
import com.example.service.ReimbursementRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/reimbursementRecord")
public class ReimbursementRecordController {

    @Autowired
    private ReimbursementRecordService reimbursementRecordService;

    // 创建报销记录
    @PostMapping("/add")
    public String addReimbursementRecord(@RequestBody ReimbursementRecord record) {
        reimbursementRecordService.addReimbursementRecord(record);
        return "报销记录创建成功";
    }

    // 根据ID查询报销记录
    @GetMapping("/get/{id}")
    public ReimbursementRecord getReimbursementRecordById(@PathVariable int id) {
        return reimbursementRecordService.getReimbursementRecordById(id);
    }


    @GetMapping("/getByInsuredPersonId/{insuredPersonId}")
    public List<ReimbursementRecord> getReimbursementRecordsByInsuredPersonId(@PathVariable int insuredPersonId) {
        return reimbursementRecordService.getReimbursementRecordsByInsuredPersonId(insuredPersonId);
    }
    // 查询所有报销记录
    @GetMapping("/all")
    public List<ReimbursementRecord> getAllReimbursementRecords() {
        return reimbursementRecordService.getAllReimbursementRecords();
    }

    // 更新报销记录
    @PutMapping("/update")
    public String updateReimbursementRecord(@RequestBody ReimbursementRecord record) {
        reimbursementRecordService.updateReimbursementRecord(record);
        return "报销记录更新成功";
    }

    // 删除报销记录
    @DeleteMapping("/delete/{id}")
    public String deleteReimbursementRecord(@PathVariable int id) {
        reimbursementRecordService.deleteReimbursementRecord(id);
        return "报销记录删除成功";
    }
}
